<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>机构管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#name").focus();
			$("#inputForm").validate({
				rules:{
                	name: {remote: "${ctx}//sys/office/isName?oldName=" + encodeURIComponent('${office.name}')},
                	loginName: {remote: "${ctx}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent('${office.loginName}')},
	                contactsPhone:{ 
	                	checkContactsPhone:true,
	                },
	                phone:{ 
	                	checkPhone:true,
	                }
	            },
	            messages: {
					loginName: {remote: "用户登录名已存在"},
					name:{remote: "代理商/个人名称已存在"}
				},
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			 $.validator.addMethod("checkContactsPhone",function(value,element,params){ 
		            var phone = /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;  
		            return this.optional(element)||(phone.test(value));  
		        },"请输入正确的11位手机号码！");
			    $.validator.addMethod("checkPhone",function(value,element,params){ 
		            var phone = /^[\d\-]+$/;  
		            return this.optional(element)||(phone.test(value));  
		        },"请输入正确的手机或者电话格式号码！");
		});
		//代理商类型选择隐藏
		function choiceType(){
			var type = $("#type").val();
			if(type == 1){//企业的信息
				$("#agentDiv").show();
			}else{
				$("#agentDiv").hide();
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/office/list?id=${office.parent.id}&types=2">代理商列表</a></li>
		<li class="active"><a href="${ctx}/sys/office/form?id=${office.id}">代理商
		<shiro:hasPermission name="sys:office:edit">修改</shiro:hasPermission>
		<shiro:lacksPermission name="sys:office:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="office" action="${ctx}/sys/office/edit" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">上级代理商:</label>
			<div class="controls">
                <input type="hidden" name="parent.id" value="${parId}"/>
				<input class="input-xlarge" style="border: 1px solid #ccc;padding: 4px 6px;" value="${officeParName}" readonly="readonly">
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">代理商类型:</label>
			<div class="controls">
				<form:select path="type" onclick="choiceType()">
					<form:options items="${fns:getDictList('agent')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">代理商/个人名称:</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="20" class="required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div id="agentDiv">
			<div class="control-group">
				<label class="control-label">企业注册地址:</label>
				<div class="controls">
					<form:input path="address" htmlEscape="false" class="required" maxlength="20"/>
					<span class="help-inline"><font color="red">*</font> </span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">企业注册号:</label>
				<div class="controls">
					<form:input path="bussregNo" htmlEscape="false" class="required" maxlength="20"/>
					<span class="help-inline"><font color="red">*</font> </span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">营业执照失效时间:</label>
				<div class="controls">
					<input value='<fmt:formatDate value="${office.expirtTime}"/>' path="expirtTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required date"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
					<span class="help-inline"><font color="red">*</font> </span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">法人姓名:</label>
				<div class="controls">
					<form:input path="contactsName" htmlEscape="false" class="required" maxlength="20"/>
					<span class="help-inline"><font color="red">*</font> </span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">法人手机号:</label>
				<div class="controls">
					<form:input path="contactsPhone" htmlEscape="false" class="required" maxlength="11"/>
					<span class="help-inline"><font color="red">*</font> </span>
				</div>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">联系电话:</label>
			<div class="controls">
				<form:input path="phone" htmlEscape="false" maxlength="20"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">邮箱:</label>
			<div class="controls">
				<form:input path="email" htmlEscape="false" maxlength="20"/>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">卡号:</label>
			<div class="controls">
				<form:input path="cardNo" class="required" htmlEscape="false" maxlength="30"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">持卡人:</label>
			<div class="controls">
				<form:input path="cardName" class="required" htmlEscape="false" maxlength="10"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">手续费:</label>
			<div class="controls">
				<form:input path="fee" maxlength="5" number="3,2" htmlEscape="false" class="number required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注:</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="input-xlarge"/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="sys:office:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>